<template>
  <div class="orderStatus">
    <div class="wrap" v-if="orderDetail">
      <div class="topIcon">
        <van-icon
          :name="orderDetail._status._type == 0 ? 'clear' : 'checked'"
          :style="{
            color: orderDetail._status._type == 0 ? '#999999' : '#25c9c3',
          }"
        ></van-icon>
      </div>
      <div class="title">
        {{ orderDetail._status._type == 0 ? "订单支付失败" : "订单支付成功" }}
      </div>
      <div class="info">
        <p>
          <span>订单编号</span
          ><span class="info_r">{{ orderDetail.order_id }}</span>
        </p>
        <p>
          <span>下单时间</span
          ><span class="info_r">{{ orderDetail._add_time }}</span>
        </p>
        <p>
          <span>支付方式</span
          ><span class="info_r">{{
            orderDetail.pay_type == "yue" ? "余额支付" : "微信支付"
          }}</span>
        </p>
        <p>
          <span>支付金额</span
          ><span class="info_r">￥{{ orderDetail.pay_price }}</span>
        </p>
      </div>
      <div class="bottomBtn">
        <van-button
          round
          color="#25c9c3"
          class="btn"
          block
          @click="$router.push(`/order/detail/${orderDetail.order_id}`)"
          >查看订单</van-button
        >
        <van-button round color="#25c9c3" class="btn" plain block @click="back"
          >返回</van-button
        >
      </div>
    </div>
  </div>
</template>

<script>
import { mapMutations } from "vuex";
export default {
  name: "OrderStatus",
  data() {
    return {
      orderDetail: null,
    };
  },
  props: ["orderId"],
  created() {
    this.getOrderDetail();
  },
  methods: {
    ...mapMutations(["changeLoading"]),
    back() {
      if (window.history.length <= 1) {
        this.$router.push("/");
      } else {
        this.$router.go(-1);
      }
    },
    getOrderDetail() {
      this.changeLoading(true);
      this.$axios.get(`/api/order/detail/${this.orderId}`).then((d) => {
        this.changeLoading(false);
        console.log("order/detail", d.data);
        if (d.data.status == 200) {
          this.orderDetail = d.data.data;
        } else if (d.data.status == 410000) {
          this.$toast.fail("请重新登录");
          this.$store.commit("loginOut");
          this.$router.push("/login");
        } else {
          this.$toast.fail(d.data.msg);
          if (window.history.length <= 1) {
            this.$router.push("/");
          } else {
            this.$router.go(-1);
          }
        }
      });
    },
  },
};
</script>

<style lang="less" scoped>
.orderStatus {
  .wrap {
    width: 93%;
    position: fixed;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    background: #fff;
    padding: 30px 15px 15px 15px;
    box-sizing: border-box;
    border-radius: 5px;
    .topIcon {
      position: absolute;
      top: 0;
      left: 50%;
      transform: translate(-50%, -50%);
      .van-icon {
        display: block;
        font-size: 60px;
      }
    }
    .title {
      font-weight: bold;
      font-size: 16px;
      padding: 15px 0;
      text-align: center;
      border-bottom: 1px solid #f5f5f5;
    }
    .info {
      padding: 15px 10px;
      border-bottom: 1px solid #f5f5f5;
      p {
        display: flex;
        justify-content: space-between;
        font-size: 14px;
        line-height: 30px;
        .info_r {
          color: #969799;
        }
      }
    }
    .bottomBtn {
      margin-top: 15px;
      .van-button {
        height: 40px;
        &:not(:first-of-type) {
          margin-top: 10px;
        }
      }
    }
  }
}
</style>